<link  href="__PLU__/bootstrap-validator/bootstrapValidator.min.css" rel="stylesheet">
<link  href="__PLU__/magic-check/css/magic-check.min.css" rel="stylesheet">
<link  href="__PLU__/bootstrap-select/bootstrap-select.min.css" rel="stylesheet">
<link  href="__PLU__/switchery/switchery.min.css" rel="stylesheet">
<script src="__PLU__/bootstrap-validator/bootstrapValidator.min.js"></script>
<script src="__PLU__/bootstrap-select/bootstrap-select.min.js"></script>
<script src="__PLU__/switchery/switchery.min.js"></script>
<script src="__PLU__/bootbox/bootbox.min.js"></script>
<div class="modal fade" id="apis-modal" role="dialog" tabindex="-1" aria-labelledby="apis-modal" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <!--Modal header-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><i class="pci-cross pci-circle"></i></button>
                <h4 class="modal-title">添加接口</h4>
            </div>
            <!--Modal body-->
            <div class="modal-body">
                <form id="apis-form" class="form-horizontal" action="{:url('api/apis/add')}" method="post">
                    <div class="tab-content">
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-name">接口名称</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" id="api-name" name="api[name]">
                                <input type="hidden" id="api-id" name="api[id]" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-category">接口分类</label>
                            <div class="col-lg-6" style="padding-left: 11px;">
                                <select class="selectpicker col-lg-5 pad-no mar-rgt" id="api-project" name="api[project]">
                                    <option value="">无</option>
                                    {foreach $projects as $project}
                                        <option value="{$project.id}">{$project.classifyname}</option>
                                    {/foreach}
                                </select>
                                <select class="selectpicker col-lg-5 pad-no" id="api-category" name="api[category]">
                                    <option value="">无</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-version">接口版本</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" id="api-version" name="api[version]">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-gateway">外网地址</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" id="api-gateway" name="api[gateway]">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-local">内网地址</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" id="api-local" name="api[local]">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-description">接口描述</label>
                            <div class="col-lg-8">
                                <textarea class="form-control" id="api-description" name="api[description]" rows="4"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-name">请求方式</label>
                            <div class="col-lg-6">
                                <div class="radio">

                                    <input id="api-type-post" class="magic-radio" type="radio" name="api[type]" value="2" checked>
                                    <label for="api-type-post">POST</label>
                                    <input id="api-type-get" class="magic-radio" type="radio" name="api[type]" value="1" >
                                    <label for="api-type-get">GET</label>
                                    <input id="api-type-put" class="magic-radio" type="radio" name="api[type]" value="3">
                                    <label for="api-type-put">PUT</label>
                                    <input id="api-type-delete" class="magic-radio" type="radio" name="api[type]" value="4">
                                    <label for="api-type-delete">DELETE</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-name">请求参数</label>
                            <div class="col-lg-9">
                                <div class="panel">
                                    <div class="panel-heading">
                                        <ul class="nav nav-tabs">
                                            <li class="active"><a data-toggle="tab" href="#param-header">HEADER请求参数</a></li>
                                            <li><a data-toggle="tab" href="#param-notype">POST请求参数</a></li>
                                        </ul>
                                    </div>
                                    <div class="panel-body pad-no">
                                        <div class="tab-content">
                                            <div id="param-header" class="tab-pane fade in active">
                                                <table class="table table-striped">
                                                    <colgroup>
                                                        <col width="15%">
                                                        <col width="15%">
                                                        <col width="15%">
                                                        <col width="35%">
                                                        <col width="10%">
                                                        <col width="10%">
                                                    </colgroup>
                                                    <thead class="bg-gray-dark">
                                                        <tr>
                                                            <th class="text-center">参数名称</th>
                                                            <th class="text-center">参数类型</th>
                                                            <th class="text-center">是否必须</th>
                                                            <th class="text-center">描述</th>
                                                            <th class="text-center">默认值</th>
                                                            <th class="text-center">操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody id="header-param-btody">
                                                        <tr>
                                                            <td class="text-center"><input type="text" class="form-control col-sm-12" name="api[param][header][field][]"></td>
                                                            <td class=" pad-ver">
                                                                <select class="selectpicker pad-no form-control col-sm-12"  name="api[param][header][type][]">
                                                                    <option value="string">string</option>
                                                                    <option value="array">array</option>
                                                                    <option value="int">int</option>
                                                                    <option value="double">double</option>
                                                                    <option value="bool">bool</option>
                                                                </select>
                                                            </td>
                                                            <td class="pad-ver text-center">
                                                                <input id="api-param-header-must-0" type="checkbox" checked>
                                                                <input id="api-param-header-must-0-value" name="api[param][header][must][]" type="hidden" value="true">
                                                            </td>
                                                            <td>
                                                                <input type="text" class="form-control col-sm-12" name="api[param][header][des][]">
                                                            </td>
                                                            <td class="text-center">
                                                                <input type="text" class="form-control col-sm-12" name="api[param][header][default][]">
                                                            </td>
                                                            <td class="text-center">
                                                                <button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <button type="button" class="btn btn-primary" onclick="addParamLine('header');"><i class="fa fa-plus-circle"></i> 添加</button>
                                            </div>
                                            <div id="param-notype" class="tab-pane fade">
                                                <table class="table table-striped">
                                                    <colgroup>
                                                        <col width="15%">
                                                        <col width="15%">
                                                        <col width="15%">
                                                        <col width="35%">
                                                        <col width="10%">
                                                        <col width="10%">
                                                    </colgroup>
                                                    <thead class="bg-gray-dark">
                                                        <tr>
                                                            <th class="text-center">参数名称</th>
                                                            <th class="text-center">参数类型</th>
                                                            <th class="text-center">是否必须</th>
                                                            <th class="text-center">描述</th>
                                                            <th class="text-center">默认值</th>
                                                            <th class="text-center">操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody id="other-param-btody">
                                                        <tr>
                                                            <td class="text-center"><input type="text" class="form-control col-sm-12" name="api[param][other][field][]"></td>
                                                            <td class=" pad-ver">
                                                                <select class="selectpicker pad-no form-control col-sm-12"  name="api[param][other][type][]">
                                                                    <option value="string">string</option>
                                                                    <option value="array">array</option>
                                                                    <option value="int">int</option>
                                                                </select>
                                                            </td>
                                                            <td class="pad-ver text-center">
                                                                <input id="api-param-other-must-0" type="checkbox" checked>
                                                                <input id="api-param-other-must-0-value" name="api[param][other][must][]" type="hidden" value="true">
                                                            </td>
                                                            <td>
                                                                <input type="text" class="form-control col-sm-12" name="api[param][other][des][]">
                                                            </td>
                                                            <td class="text-center">
                                                                <input type="text" class="form-control col-sm-12" name="api[param][other][default][]">
                                                            </td>
                                                            <td class="text-center">
                                                                <button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <button type="button" class="btn btn-primary" onclick="addParamLine('other');"><i class="fa fa-plus-circle"></i> 添加</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-name">响应参数</label>
                            <div class="col-lg-9">
                                <table class="table table-striped">
                                    <colgroup>
                                        <col width="15%">
                                        <col width="15%">
                                        <col width="15%">
                                        <col width="35%">
                                        <col width="10%">
                                        <col width="10%">
                                    </colgroup>
                                    <thead class="bg-gray-dark">
                                        <tr>
                                            <th class="text-center">参数名称</th>
                                            <th class="text-center">参数类型</th>
                                            <th class="text-center">是否必须</th>
                                            <th class="text-center">描述</th>
                                            <th class="text-center">默认值</th>
                                            <th class="text-center">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="response-param-btody">
                                        <tr>
                                            <td class="text-center"><input type="text" class="form-control col-sm-12" name="api[param][response][field][]"></td>
                                            <td class=" pad-ver">
                                                <select class="selectpicker pad-no form-control col-sm-12"  name="api[param][response][type][]">
                                                    <option value="string">string</option>
                                                    <option value="array">array</option>
                                                    <option value="int">int</option>
                                                </select>
                                            </td>
                                            <td class="pad-ver text-center">
                                                <input id="api-param-response-must-0" type="checkbox" checked>
                                                <input id="api-param-response-must-0-value" name="api[param][response][must][]" type="hidden" value="true">
                                            </td>
                                            <td>
                                                <input type="text" class="form-control col-sm-12" name="api[param][response][des][]">
                                            </td>
                                            <td class="text-center">
                                                <input type="text" class="form-control col-sm-12" name="api[param][response][default][]">
                                            </td>
                                            <td class="text-center">
                                                <button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                <button type="button" class="btn btn-primary" onclick="addParamLine('response');"><i class="fa fa-plus-circle"></i> 添加</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-response">返回示例</label>
                            <div class="col-lg-8">
                                <textarea class="form-control" id="api-response" name="api[response]" rows="5"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-offset-1 col-lg-1 control-label" for="api-name">错误码</label>
                            <div class="col-lg-9">
                                <table class="table table-striped">
                                    <colgroup>
                                        <col width="15%">
                                        <col width="70%">
                                        <col width="15%">
                                    </colgroup>
                                    <thead class="bg-gray-dark">
                                        <tr>
                                            <th class="text-center">错误码</th>
                                            <th class="text-center">描述</th>
                                            <th class="text-center">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="error-codes-btody">
                                        <tr>
                                            <td class="text-center"><input type="text" class="form-control col-sm-12" name="api[error][status][]"></td>
                                            <td>
                                                <input type="text" class="form-control col-sm-12" name="api[error][des][]">
                                            </td>
                                            <td class="text-center">
                                                <button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                <button type="button" class="btn btn-primary" onclick="addErrorLine('#error-codes-btody');"><i class="fa fa-plus-circle"></i> 添加</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <!--Modal footer-->
            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                <button class="btn btn-primary" form="apis-form" type="button">保存</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        switchInit('api-param-header-must-0','api-param-header-must-0-value');
        switchInit('api-param-other-must-0','api-param-other-must-0-value');
        switchInit('api-param-response-must-0','api-param-response-must-0-value');
        $('input[name="api[type]"]').on('click',function(){
            var inputid = $(this).attr('id');
            var typelabel = $('label[for="'+inputid+'"]').text();
            $('a[href="#param-notype"]').text(typelabel+'请求参数');
        });
        $('#apis-form').bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon',
                invalid: 'glyphicon',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                'api[name]': {
                    validators: {
                        notEmpty: {
                            message: '请输入接口名称'
                        }
                    }
                },
                'api[version]': {
                    validators: {
                        notEmpty: {
                            message: '请输入接口版本',
                        }
                    }
                },
                'api[gateway]': {
                    validators: {
                        notEmpty: {
                            message: '请输入外网地址',
                        }
                    }
                },
                'api[local]':{
                    validators: {
                        notEmpty: {
                            message: '请输入内网地址',
                        }
                    }
                },
                'api[project]':{
                    validators: {
                        notEmpty: {
                            message: '请选择项目',
                        }
                    }
                },
                'api[category]':{
                    validators: {
                        notEmpty: {
                            message: '请选择分类',
                        }
                    }
                },
                'api[description]':{
                    validators: {
                        notEmpty: {
                            message: '请输入接口描述',
                        }
                    }
                },
                'api[response]':{
                    validators: {
                        notEmpty: {
                            message: '请输入接口描述',
                        }
                    }
                }
            }
        });
    });
    var submit_status = false;
    $('button[form="apis-form"]').on('click',function(){
        $('#apis-form').data('bootstrapValidator').validate();  
        if(!$('#apis-form').data('bootstrapValidator').isValid()){  
            return false;
        }
        if(submit_status == true){
            return false;
        }else{
            submit_status = true;
        }
        $.ajax({
            url:"{:url('api/apis/save_api')}",
            type:"post",
            data:$('#apis-form').serialize(),
            dataType:"json",
            success:function(result){
                if(result.status == 'success'){
                    $('#apis-modal').modal('hide');
                    $.niftyNoty({
                        type: 'success',
                        icon : 'pli-exclamation icon-2x',
                        message : result.msg,
                        container : 'floating',
                        timer : 1500,
                    });
                    setTimeout(function(){
                        window.location.reload();
                    },1500);
                }else{
                    $.niftyNoty({
                        type: 'warning',
                        icon : 'pli-exclamation icon-2x',
                        message : result.msg,
                        container : 'floating',
                        timer : 1500,
                    });
                    submit_status = false;
                }
            },
            error:function(){
                $.niftyNoty({
                    type: 'danger',
                    icon : 'pli-exclamation icon-2x',
                    message : '网络连接失败',
                    container : 'floating',
                    timer : 1500,
                });
                submit_status = false;
            }
        });
    });

    function getCategories(catid){
        $.ajax({
            url:"{:url('api/projects/getdata')}",
            type:"post",
            data:{"catid":catid},
            dataType:"json",
            success:function(result){
                if(result.status == 'success'){
                    $('#api-category').html('');
                    var categories = result.data.categories;
                    var option = null;
                    for(var i=0;i<categories.length;i++){
                        option ='<option value="'+categories[i].id+'">'+categories[i].classifyname+'</option>';
                        $('#api-category').append($(option));
                    }
                    $('#api-category').selectpicker('refresh');
                }else{
                    $.niftyNoty({
                        type: 'warning',
                        icon : 'pli-exclamation icon-2x',
                        message : result.msg,
                        container : 'floating',
                        timer : 1500,
                    });
                }
            },
            error:function(){
                $.niftyNoty({
                    type: 'danger',
                    icon : 'pli-exclamation icon-2x',
                    message : '网络连接失败',
                    container : 'floating',
                    timer : 1500,
                });
            }
        });
    }

    $('#api-project').on('change',function(){
        if($(this).val()==''){
            $('#api-category').html('');
            $('#api-category').append($('<option value="">无</option>'));
            $('#api-category').selectpicker('refresh');
            return false;
        }
        var catid = $(this).val();
        getCategories(catid);
    });
    function switchInit(inputid,spanid){
        var changeCheckbox = document.getElementById(inputid),
            changeField = document.getElementById(spanid);
        new Switchery(changeCheckbox, {color:'#35b9e7'});
        changeCheckbox.onchange = function() {
            changeField.value = changeCheckbox.checked;
        };
    }

    function delparamLine(e){
        $($(e).parents("tr")).detach();
    }

    var randomtime = Date.parse(new Date());

    function addErrorLine(tbodyid){
        nowtime = Date.parse(new Date());
        if(randomtime == nowtime){
            return false;
        }
        randomtime = nowtime;
        var tr = ' <tr>';
            tr = tr+'<td class="text-center"><input type="text" class="form-control col-sm-12" name="api[error][status][]"></td>';
            tr = tr+'<td>';
            tr = tr+'<input type="text" class="form-control col-sm-12" name="api[error][des][]">';
            tr = tr+'</td>';
            tr = tr+'<td class="text-center">';
            tr = tr+'<button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>';
            tr = tr+'</td>';
            tr = tr+'</tr>';
        $(tbodyid).append($(tr));
    }

    function jsonCodeLine(json,tbodyid){
        var tr = ' <tr>';
            tr = tr+'<td class="text-center"><input type="text" class="form-control col-sm-12" name="api[error][status][]" value="'+json.status+'"></td>';
            tr = tr+'<td>';
            tr = tr+'<input type="text" class="form-control col-sm-12" name="api[error][des][]" value="'+json.des+'">';
            tr = tr+'</td>';
            tr = tr+'<td class="text-center">';
            tr = tr+'<button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>';
            tr = tr+'</td>';
            tr = tr+'</tr>';
        $(tbodyid).append($(tr));
    }

    function addParamLine(paramtype){
        nowtime = Date.parse(new Date());
        if(randomtime == nowtime){
            return false;
        }
        randomtime = nowtime;
        var inputid = "api-param-"+paramtype+"-must-"+randomtime,
            spanid  = "api-param-"+paramtype+"-must-"+randomtime+"-value",
            selectid = "api-param-"+paramtype+"-type-"+randomtime;
        var tr = '<tr>';
            tr = tr+'<td class="text-center"><input type="text" class="form-control col-sm-12" name="api[param]['+paramtype+'][field][]"></td>';
            tr = tr+'<td class=" pad-ver">';
            tr = tr+'<select class="selectpicker pad-no form-control col-sm-12" id="'+selectid+'" name="api[param]['+paramtype+'][type][]">';
            tr = tr+'<option value="string">string</option>';
            tr = tr+'<option value="array">array</option>';
            tr = tr+'<option value="int">int</option>';
            tr = tr+'<option value="double">double</option>';
            tr = tr+'<option value="bool">bool</option>';
            tr = tr+'</select>';
            tr = tr+'</td>';
            tr = tr+'<td class="pad-ver text-center">';
            tr = tr+'<input id="'+inputid+'" type="checkbox" checked>';
            tr = tr+'<input id="'+spanid+'" name="api[param]['+paramtype+'][must][]" type="hidden" value="true">';
            tr = tr+'</td>';
            tr = tr+'<td>';
            tr = tr+'<input type="text" class="form-control col-sm-12" name="api[param]['+paramtype+'][des][]">';
            tr = tr+'</td>';
            tr = tr+'<td class="text-center">';
            tr = tr+'<input type="text" class="form-control col-sm-12" name="api[param]['+paramtype+'][default][]">';
            tr = tr+'</td>';
            tr = tr+'<td class="text-center">';
            tr = tr+'<button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>';
            tr = tr+'</td>';
            tr = tr+'</tr>';
        $("#"+paramtype+"-param-btody").append($(tr));
        switchInit(inputid,spanid);
        $('#'+selectid).selectpicker();
    }
    function jsonParamLine(keyid,json,paramtype){
        var inputid  = "api-param-"+paramtype+"-must-"+keyid,
            spanid   = "api-param-"+paramtype+"-must-"+keyid+"-value",
            selectid = "api-param-"+paramtype+"-type-"+keyid;
        var tr = '<tr>';
            tr = tr+'<td class="text-center"><input type="text" class="form-control col-sm-12" name="api[param]['+paramtype+'][field][]" value="'+json.field+'"></td>';
            tr = tr+'<td class=" pad-ver">';
            tr = tr+'<select class="selectpicker pad-no form-control col-sm-12" id="'+selectid+'" name="api[param]['+paramtype+'][type][]" >';
            tr = tr+'<option value="string">string</option>';
            tr = tr+'<option value="array">array</option>';
            tr = tr+'<option value="int">int</option>';
            tr = tr+'<option value="double">double</option>';
            tr = tr+'<option value="bool">bool</option>';
            tr = tr+'</select>';
            tr = tr+'</td>';
            tr = tr+'<td class="pad-ver text-center">';
            if(json.must =='true'){
                tr = tr+'<input id="'+inputid+'" type="checkbox" checked>';
            }else{
                tr = tr+'<input id="'+inputid+'" type="checkbox">';
            }
            tr = tr+'<input id="'+spanid+'" name="api[param]['+paramtype+'][must][]" type="hidden" value="'+json.must+'">';
            tr = tr+'</td>';
            tr = tr+'<td>';
            tr = tr+'<input type="text" class="form-control col-sm-12" name="api[param]['+paramtype+'][des][]" value="'+json.des+'">';
            tr = tr+'</td>';
            tr = tr+'<td class="text-center">';
            tr = tr+'<input type="text" class="form-control col-sm-12" name="api[param]['+paramtype+'][default][]" value="'+json.default+'">';
            tr = tr+'</td>';
            tr = tr+'<td class="text-center">';
            tr = tr+'<button type="button" class="btn btn-default" onclick="delparamLine(this);"><i class="ion-trash-b"></i></button>';
            tr = tr+'</td>';
            tr = tr+'</tr>';
        $("#"+paramtype+"-param-btody").append($(tr));
        switchInit(inputid,spanid);
        $('#'+selectid).val(json.type);
        $('#'+selectid).selectpicker('render');
        
    }
    $('#apis-modal').on('show.bs.modal', function (e) {
        var apiid = $($(e)[0].relatedTarget).data('apiid');
        if(apiid == undefined){
            $('#apis-form').bootstrapValidator('resetForm', true);
            $('#api-id').val('');
            $('#header-param-btody').html('');
            $('#other-param-btody').html('');
            $('#response-param-btody').html('');
            $('#error-codes-btody').html('');
            addParamLine('header');
            randomtime -= 2000;
            addParamLine('other');
            randomtime -= 3000;
            addParamLine('response');
            addErrorLine('#error-codes-btody');
        }else{
            $.ajax({
                url:"{:url('api/apis/get')}",
                type:"post",
                data:{'apiid':apiid},
                dataType:"json",
                success:function(result){
                    if(result.status == 'success'){ 
                        var detail = result.data.detail;
                            list = result.data.list;
                            param = result.data.param;
                        $('#api-name').val(list.apiname);
                        $('#api-id').val(list.id);
                        $('#api-version').val(detail.version);
                        $('#api-gateway').val(detail.gateway);
                        $('#api-local').val(detail.local);
                        $('#api-description').val(detail.description);
                        $('#api-response').val(detail.goback);
                        $('input[name="api[type]"][value="'+param.type+'"]').click();
                        //$('input[name="api[type]"][value="'+param.type+'"]').prop('checked',true);
                        var response = JSON.parse(param.response),
                            header   = JSON.parse(param.header),
                            error    = JSON.parse(param.statuscode),
                            categories = list.categories,
                            request  = JSON.parse(param.request);
                        var resjson = response[param.apitype];
                            reqjson = request[param.apitype];

                        for(var i=0;i<categories.length;i++){
                            option ='<option value="'+categories[i].id+'">'+categories[i].classifyname+'</option>';
                            $('#api-category').append($(option));
                        }
                        $('#api-project').val(list.project);
                        $('#api-project').selectpicker('render');
                        $('#api-category').val(list.classify);
                        $('#api-category').selectpicker('render');
                        $("#response-param-btody").html('');
                        for(var i=0;i<resjson.length;i++){
                            jsonParamLine(i,resjson[i],'response');
                        }
                        $("#other-param-btody").html('');
                        for(var i=0;i<reqjson.length;i++){
                            jsonParamLine(i,reqjson[i],'other');
                        }
                        $("#header-param-btody").html('');
                        for(var i=0;i<header.length;i++){
                            jsonParamLine(i,header[i],'header');
                        }
                        $('#error-codes-btody').html('');
                        for(var i=0;i<error.length;i++){
                            jsonCodeLine(error[i],'#error-codes-btody');
                        }
                    }else{
                        $.niftyNoty({
                            type: 'warning',
                            icon : 'pli-exclamation icon-2x',
                            message : result.msg,
                            container : 'floating',
                            timer : 1500,
                        });
                    }
                },
                error:function(){
                    $.niftyNoty({
                        type: 'danger',
                        icon : 'pli-exclamation icon-2x',
                        message : '网络连接失败',
                        container : 'floating',
                        timer : 1500,
                    });
                }
            });
        }
    });
</script>